package com.dude.objects;
import java.util.ArrayList;

import com.dude.R;

import android.content.Context;
import android.graphics.Bitmap;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;


/* this class provides a customized adaptor to show a list of images and names 
 * 
 */
public class ImageAndTextArrayAdapter extends ArrayAdapter<GenericPair<String, Bitmap>>{

	protected Context context;
	protected ArrayList<GenericPair<String, Bitmap>> values;
	protected boolean vertical;

	
	public ImageAndTextArrayAdapter(Context context, ArrayList<GenericPair<String, Bitmap>> values)
	{
		this(context, values, false);
	}
	
	public ImageAndTextArrayAdapter(Context context, ArrayList<GenericPair<String, Bitmap>> values, boolean vertical)
	{
		super(context, R.layout.image_and_text_list_item, values);
	    this.context = context;
	    this.values = values;
	    this.vertical =vertical;
	}
	
	public View getView(int position, View convertView, ViewGroup parent) {
	    LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
	    
	    View rowView;
	    if (!vertical)
	    	rowView = inflater.inflate(R.layout.image_and_text_list_item, parent, false);
	    else
	    	rowView = inflater.inflate(R.layout.image_and_text_list_item_vertical, parent, false);
	    
	    TextView textView = (TextView) rowView.findViewById(R.id.txt_id);
	    ImageView imageView = (ImageView) rowView.findViewById(R.id.img_id);	    	    
	    textView.setText(values.get(position).getFirst());
	    // set the images in each line
	    Bitmap bitmap = values.get(position).getSecond();
	    imageView.setImageBitmap(bitmap);
	    return rowView;
	  }
	
	
}
